﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Common
//  File name:	MetaFormScript.cs
//  Developer:	Solomatov Igor
//  Created:	15.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System;
using System.Linq;

namespace Smart.Common.Forms
{
	/// <summary>
	/// Forms JavaScript
	/// </summary>
	public class MetaFormScript : MetaFormCtrl
	{
		/// <summary>
		/// Script source url
		/// </summary>
		public string Src { get; set; }

		/// <summary>
		/// Script source text
		/// </summary>
		public string Text { get; set; }

		/// <summary>
		/// Script displacement
		/// </summary>
		public MetaFormScriptDisplacement Displacement { get; set; }

		/// <summary>
		/// Script security
		/// </summary>
		public string[] Security { get; set; }

		/// <summary>
		/// Script condition
		/// </summary>
		public string Condition { get; set; }

		/// <summary>
		/// Forms JavaScript
		/// </summary>
		public MetaFormScript(string name, string src, string text, MetaFormScriptDisplacement displacement)
			: base(null, name)
		{
			if (src.IsNullOrEmpty())
				src = null;

			if (text.IsNullOrEmpty())
				text = null;

			Src = src;
			Text = text;
			Displacement = displacement;
		}

		/// <summary>
		/// Set security
		/// </summary>
		/// <param name="security">;# splitted string of security</param>
		public virtual void SetSecurity(string security)
		{
			Security = security.SplitAndTrimByCommaOrSemicolonOrLookup();
		}
	}
}